<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-button type="primary" @click="handleAdd">新增</el-button>
					<el-button type="primary" @click="getAppMediaArray">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="tagsList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column prop="id" label="序号" width="70" />
             <el-table-column prop="thumbUrl" label="正常图标" width="120" >
                 <template scope="scope">
                   	<a target="_blank" :href="scope.row.thumbUrl" class="" style="text-align: center;display: inline-block;">
                        <img :src="scope.row.thumbUrl" alt="" style="text-align: center; width:100%; padding-left:-20px;">
                    </a>
                 </template>
            </el-table-column>
			<el-table-column prop="title" label="名称" width="200" />
			<el-table-column prop="describe" label="描述" width="200">
			</el-table-column>
            <el-table-column prop="authorName" label="作者名称" width="100"/>
			<el-table-column prop="authorHeaderUrl" label="作者头像" width="120" >
                 <template scope="scope">
                   	<a target="_blank" :href="scope.row.authorHeaderUrl" class="" style="text-align: center;display: inline-block;">
                        <img :src="scope.row.authorHeaderUrl" alt="" style="text-align: center; width:100%; padding-left:-20px;">
                    </a>
                 </template>
            </el-table-column>
            <el-table-column prop="sort" label="排序" sortable/>
            <el-table-column prop="readNumber" label="阅读量" width="120">
			</el-table-column>
			<el-table-column prop="type" label="类型"width="95" sortable/>
            </el-table-column>
			<el-table-column prop="jumpUrl" label="跳转链接" width="295" sortable/>
            </el-table-column>
			<el-table-column prop="isValid" label="状态" sortable>
    			<template scope="scope">
                       {{scope.row.isValid=='1'?"已上线":"未上线"}}
                </template>
			</el-table-column>
			 <el-table-column prop="updateTime" label="更新时间" width="185"sortable/>
            </el-table-column>
			<el-table-column prop="createTime" label="创建时间" width="185"sortable/>
			<el-table-column label="操作" width="250" fixed="right">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button type="danger" size="small" @click="handleStatus(scope.$index, scope.row)"> {{scope.row.isValid=='1'?"下线":"上线"}}</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<el-dialog title="编辑" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" ref="editForm" >
				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:45px">标题</span>
							<el-col :span="2" style="width: 440px;margin-left:5px;">
								<div style="width:440px;">
									<template>
										<el-input v-model="editForm.title"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:45px">描述</span>
							<el-col :span="2" style="width: 440px;margin-left:5px;">
								<div style="width:440px;">
									<template>
										<el-input v-model="editForm.describe"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>
				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:35px">缩略图</span>
							<el-col :span="2" style="width: 440px;margin-left:5px;">
								<div style="width:440px;">
									<template>
										<el-input v-model="editForm.thumbUrl"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>
				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:20px">跳转链接</span>
							<el-col :span="2" style="width: 440px;margin-left:5px;">
								<div style="width:440px;">
									<template>
										<el-input v-model="editForm.jumpUrl"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>
                <el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
					<span style="padding-left:25px">作者名称</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.authorName"></el-input>
									</template>
								</div>
							</el-col>
						<span style="padding-left:10px;margin-left:35px;">阅读量</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.readNumber"></el-input>
									</template>
								</div>
						</el-col>
					</el-row>
				</el-form-item>

				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:20px">作者头像</span>
							<el-col :span="2" style="width: 440px;margin-left:5px;">
								<div style="width:440px;">
									<template>
										<el-input v-model="editForm.authorHeaderUrl"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
					<span style="padding-left:50px">排序</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.sort"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
					
						<span style="padding-left:50px">类型</span>
						<el-col :span="2" style="width: 180px;margin-left:15px;">
								<div style="width:260px;">
									<template>
											<el-radio v-model="editForm.type" label="common">普通</el-radio>
											<el-radio v-model="editForm.type" label="hot">热评</el-radio>
											<el-radio v-model="editForm.type" label="main">主贴</el-radio>
									</template>
								</div>
						</el-col>
						<span style="padding-left:50px" >上线</span>
						<el-col :span="2" style="width: 180px;margin-left:15px;">
								<template>
											<el-radio v-model="editForm.isValid" label="1">是</el-radio>
											<el-radio v-model="editForm.isValid" label="0">否</el-radio>
								</template>
							</el-col>
					</el-row>
				</el-form-item>

			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="addLoading">确定</el-button>
			</div>
		</el-dialog>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	import {
		getAppMediaList,
		updateAppMedia

	} from '../../api/api';
	export default {
		data() {
			return {
				filters: {
					keyword: ''
                },
                addLoading:false,
				isShow:'1',
				tagsList: [],
				total: 0,
				page: 1,
				pageSize: 10,
				listLoading: false,
				sels: [], //列表选中列
				editFormVisible: false, //编辑界面是否显示
				editLoading: false,
				//编辑界面数据
				editForm: {
					
				},
				//新增界面数据
				addForm: {
				
                },
                
			}
		},
		methods: {
			handleCurrentChange(val) {
				this.page = val;
				this.getAppMediaArray();
			},
			//获取用户列表
			getAppMediaArray() {
                this.listLoading = true;
                let param = Object.assign({}, {
                    page:1,
                    limit:10
                });
				getAppMediaList(param).then((res) => {
					let result = res.data
					if (result.code == "1000") {
						this.tagsList = res.data.data.cxMedias
						this.total = res.data.data.total
					}
					this.listLoading = false;
				});
			},
		
			//显示编辑界面
			handleEdit: function(index, row) {
				this.editFormVisible = true;
				console.log("--",row);
				this.editForm = Object.assign({}, row);
				this.isShow = this.editForm.isShow +''
			},
			//显示新增界面
			handleAdd: function() {
				this.isShow = '0'
                this.editFormVisible = true;
                this.editForm = {}
			},
			handleStatus: function(index, row) {
				if(row.isValid=='1'){
					row.isValid  = 0
				}else{
					row.isValid  = 1
				}
				updateAppMedia(row).then((res) => {
					this.editLoading = false;
					this.$message({
						message: '提交成功',
						type: 'success'
					});
					this.getAppMediaArray();
				});
			},
			//编辑
			editSubmit: function() {
				this.$confirm('确认提交吗？', '提示', {}).then(() => {
					this.editLoading = true;
					updateAppMedia(this.editForm).then((res) => {
						this.editLoading = false;
						this.$message({
							message: '提交成功',
							type: 'success'
						});
						this.editFormVisible = false;
						this.getAppMediaArray();
					});
				});
			},
	
			selsChange: function(sels) {
				this.sels = sels;
            },
            
		},
		
		mounted() {
			this.getAppMediaArray();
		}
	}
</script>




